package com.kingsoft.demo.xml.dom4j;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class TestReader2 {

	public void test() throws Exception{
		
		
		SAXReader sr=new SAXReader();	
		Document  doc=sr.read("src/emp.xml");
		
		Element root=doc.getRootElement();
	
		List rowlist= root.elements("ROW");
		
		//取出数据：使用jdk5.0新语法
		for(Object obj:rowlist){
				
			    //获取每一行row
				Element el_row= (Element)obj;
				List empno_list=el_row.elements("EMPNO");
				for(Object obj2 :empno_list){
					Element el_empno= (Element)obj2;
					System.out.println(el_empno.getText());
				}
		}
		
		//-------------------------------------
		//取出数据:使用一般for循环
		for(int i=0;i<rowlist.size();i++){
			
			Element el_row =(Element)rowlist.get(i);
			List empno_list = el_row.elements("EMPNO");
			for(int j=0;j<empno_list.size();j++){
				Element el_empno=(Element)empno_list.get(j);
				System.out.println(el_empno.getText());
			}
		}
		
	}
	public static void main(String []args){
		
		TestReader2 tr=new TestReader2();
		try{
			tr.test();
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
